import javax.swing.*;
import java.awt.*;
import java.util.Random;

/*
May 3, 2013
Monster.java
Erich Hauck
 */

public class Monster extends JPanel
{

   //used for character movement
   private ImageIcon imageArray[];
   Image monst;
   Rectangle monsterBox;
   private int width;
   private int height;
   //sees if the monster is alive
   boolean alive;
   public int life=3;
   private int /*how many pictures*/totalFrames = 12 ,/*frame you are on*/ currentFrame =0;
   
   //creates the placement for the shape
   int x, y, vx=0, vy=0, counter=0, direction;
   Random rand = new Random();
   int move=1;
   boolean moveUp, moveDown, moveLeft, moveRight;
   
   public Monster()
   {
      
      
    //creates array for images
      
      imageArray = new ImageIcon[totalFrames];
      
      
      //adds every image icon in order to the array
      for (int i =0; i<3;i++)
      {
         imageArray[i] = new ImageIcon("Mb"+(i+1)+".png");
         
      }
      for (int i =3; i<6;i++)
      {
         imageArray[i] = new ImageIcon("MF"+(i-2)+".png");
         
      }
      for (int i =6; i<9;i++)
      {
         imageArray[i] = new ImageIcon("ML"+(i-5)+".png");
         
      }
      for (int i =9; i<12;i++)
      {
         imageArray[i] = new ImageIcon("MR"+(i-8)+".png");
         
      }
      monst = imageArray[currentFrame].getImage();
      x=rand.nextInt(600);
      y=rand.nextInt(600);
      //gets height and width of image
      width = monst.getWidth(null);
      height = monst.getHeight(null);
      
      //creates monster bounds
      monsterBox = new Rectangle(x, y, width, height);
      //sets the monster to be alive
      alive = true;
      direction=0;
   }
   //determines weather or not the monster is alive
   
   public boolean getLife()
   {
      return alive;
   }
   public void kill()
   {
      alive=false;
   }
   
   public void hurt()
   {
	   life--;
	   if(life==0)
	   {
		      alive=false;
	   }
	   		
   }
   
   //determines movement
   public void createDirection()
   {    
      direction = rand.nextInt(5);
   }
   //directions
   
   public int getDirection()
   {
      return direction;
   }
   public void up()
   {
      vy=-1;
      vx=0;
   }
   public void down()
   {
      vy=1;
      vx=0;
   }
   public void left()
   {
      vx=-1;
      vy=0;
   }
   public void right()
   {
      vx=1;
      vy=0;
   }
   public void stop()
   {
      vx=0;
      vy=0;
   }
   //makes the character move
   public void move()
   {
      x+=vx;
      y+= vy;
   }
   
   
   //gets X and Y
   
   public int getX()
   {
      return x;
   }
   public int getY()
   {
      return y;
   }
   public void setX(int inputx)
   {
      x = inputx;
   }
   public void setY(int inputy)
   {
      y= inputy;
   }
   
   public int getWidth()
   {
      return width;
   }
   public int getHeight()
   {
      return height;
   }
 //gets the bounds of the player
   public Rectangle getBounds() 
   {
       return monsterBox;
   }
   public void changeBounds()
   {
      monsterBox = new Rectangle(x, y, width, height);
   }
   
   //returns image
   public Image getSprite()
   {
      return monst;
   }

   //alters the frames
   public void setFrame(int input)
   {
      currentFrame = input;
   }
   public int getFrame()
   {
      return currentFrame;
   }
   public void changeFrame()
   {
      currentFrame++;
   }
   public void changeSprite()
   {
      monst = imageArray[currentFrame].getImage();
   }
 
}